#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
#define F(i,l,r) for(int i=l;i r;++i)
#define R(i,r,l) for(int i=r;i l;--i)
#define pb push_back
template<class T=int>inline int read(){
	T x=0;bool b=0;char c=getchar();
	while(c<'0'||c>'9') b|=c=='-',c=getchar();
	while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return b?-x:x;
}
inline char readc(){
	char c=getchar();
	while(isspace(c)) c=getchar();
	return c;
}
namespace{
	const int N=20;
	int n,cnt;
	bool f[N+1][1<<N];
	void dfs(int x,int S){
		if(f[x][S]) return;
		++cnt;f[x][S]=1;
		F(i,1,<x){
			if((S>>i&1)==(S>>i-1&1)||(!(S>>i&1)&&(S>>i-1&1)))
				dfs(x-2,S%(1<<i-1)+(S>>i+1<<i-1));
		}
	}
	void work(){
		ios::sync_with_stdio(0);
		string s;
		cin>>s;
		if(s.size()<=20){
			int res=0;
			reverse(s.begin(),s.end());
			for(char c:s) res=res*2+(c=='B');
			dfs(s.size(),res);
			cout<<cnt;
			return;
		}
		F(i,1,<s.size()){
			if(s[i-1]=='B'&&s[i]=='A') ++cnt;
		}
		cout<<cnt+1;
	}
}
#if 1
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#else
#define file(x)
#endif
signed main(){file("song");work();return 0;}